/*
 * @Author: yang-tengyuyxd 1282291612@qq.com
 * @Date: 2024-10-31 11:41:46
 * @LastEditors: yang-tengyuyxd 1282291612@qq.com
 * @LastEditTime: 2024-10-31 13:14:36
 * @FilePath: /yxd/管道/命名管道/Comm.hpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#pragma once

#include <iostream>
#include <string>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>

const std::string gpipeFile = "./fifo"; // 公共文件
const mode_t gmode = 0600;              // 允许拥有者 读和写 所属组和other没有任何权限
const int gdefultfd = -1;
const int gsize = 1024;
const int gForRead=O_RDONLY;
const int gForWrite=O_WRONLY;

int OpenPipe(int flag)
{
    //如果读端打开文件时 写端还没打开，读端对用的Open()就会阻塞
       int fd = ::open(gpipeFile.c_str(), flag);
        if (fd < 0)
        {
            std::cerr << "open error" << std::endl;
        }
        return fd;
}

void ClosePipeHelper(int fd)
{
          if (fd >= 0)
        {
            ::close(fd);
        }
}
